{* Smarty *}
{extends file="include/base_with_menu.tpl"}

{block name="javascript"}
<script type="text/javascript">
var tokan_name = '{$token_name|escape}',
	token_hash = '{$token_hash|escape}';
{literal}
function delete_project()
{
	if(confirm('是否要删除此项目？'))
	{
		var post_vars = {
			project_id: $('[name=project_id]').val(),
		};
		post_vars[tokan_name] = token_hash;

		$.post('/market/se/project/delete', post_vars, function(){window.location.reload()});
	}
}
function sum(parent, subclass, retclass)
{
	var c = 0;
	$(subclass, parent).each(function(){
		c += $(this).text() | 0;
	});
	$(retclass, parent).text(c);
}
function enterate(parent, successclass, failureclass, retclass)
{
	var succ = $(successclass, parent).size(),
		fail = $(failureclass, parent).size();
	if(succ == 0) {
		$(retclass, parent).text('0%');
	} else {
		var c = (succ / (succ + fail) * 1000) | 0;
		$(retclass, parent).text(c/10 + '%');
	}
}
function coverate(parent, coverclass, existsclass, retclass)
{
	var cover = 0,
		exists = 0;
	$(coverclass, parent).each(function(){
		cover += $(this).text() | 0;
	});
	$(existsclass, parent).each(function(){
		exists += $(this).text() | 0;
	});
	if(cover == 0) {
		$(retclass, parent).text('0%');
	} else {
		var c = (cover / exists * 1000) | 0;
		$(retclass, parent).text(c/10 + '%');
	}
}
function devoterate(parent, coverclass, existsclass, retclass)
{
	var cover = $(coverclass, parent).text() | 0,
		exists = $(existsclass, parent).text() | 0;
	if(cover == 0) {
		$(retclass, parent).text('0%');
	} else {
		var c = (cover / exists * 1000) | 0;
		$(retclass, parent).text(c/10 + '%');
	}
}
function pointrate(parent, pointclass, worktimeclass, projectimeclass, retclass)
{
	var point = $(pointclass, parent).text(),
		worktime = $(worktimeclass, parent).text() | 0,
		projectime = $(projectimeclass).text() | 0;
	
	if(point == 0 || worktime == 0) {
		$(retclass, parent).text('0');
	} else {
		var c = (point * worktime / projectime * 100) | 0;
		$(retclass, parent).text(c/100);
	}
}

$(function(){
	$('#school,.member').each(function(){
		sum(this, '.cover_grade', '.cover_grade_total');
		sum(this, '.exists_grade', '.exists_grade_total');
		enterate(this, '.enter_1', '.enter_2', '.enter_rate');
		coverate(this, '.cover_grade', '.exists_grade', '.cover_rate,.devote_total');
	});
	$('.member tr').each(function(){
		devoterate(this, '.cover_grade', '.exists_grade', '.devote_rate');
		pointrate(this, '.give_point', '.work_time', '.time_total', '.real_give_point');
	});
})
{/literal}
</script>
{/block}

{block name="content"}
<h3 class="blockTitle">{$project.start_time|date_format:'%Y-%m-%d'} {$project.name|escape}</h3>
<div class="layout">
    <table width="100%" class="tbData01" cellspacing="0" cellpadding="0">
        <tr>
            <th width="100" class="textRight">项目名称</th>
            <td class="textLeft" colspan="13">
                {$project.name|escape}
            </td>
        </tr>
        <tr>
            <th class="textRight">起始时间</th>
            <td class="textLeft" colspan="13">
                {$project.start_time|date_format:'%Y-%m-%d'}
            </td>
        </tr>
        <tr>
            <th class="textRight">结束时间</th>
            <td class="textLeft" colspan="13">
                {$project.end_time|date_format:'%Y-%m-%d'}
            </td>
        </tr>
        <tr>
            <th class="textRight">项目成员</th>
            <td class="textLeft" colspan="13">
                {foreach $members as $member}
                {$member.name|escape}&nbsp;&nbsp;
                {foreachelse}
				无
				{/foreach}
            </td>
        </tr>
        <tr>
            <th class="textRight">项目学校</th>
            <td class="textLeft" colspan="13">
                {foreach $schools as $school}
                <a href="/market/se/school/edit/page?school_id={$school.id}">{$school.name|escape}</a>&nbsp;&nbsp;
                {foreachelse}
				无
				{/foreach}
            </td>
        </tr>
        <tr>
            <th class="textRight">DM单附件</th>
            <td class="textLeft" colspan="13">
            	{if $project.attach_path}
                <a href="/market/se/project/attach/get?id={$project.id}">{$project.attach_name|escape}</a>
                {else}
				无
				{/if}
            </td>
        </tr>
        <tr>
            <th class="textRight">讲座地址</th>
            <td class="textLeft fB cRed" colspan="13">
            	这里有问题，没有对应表单
            </td>
        </tr>
        
        <tr>
        	<th rowspan="2">项目学校</th>
        	<th rowspan="2">进入情况</th>
        	<th rowspan="2">逐校覆盖班数</th>
        	<th rowspan="2">逐校班级总数</th>
        	<th colspan="2">预约实到并集</th>
        	<th colspan="2">报名人数</th>
        	<th rowspan="2">项目时长</th>
        	<th rowspan="2">项目覆盖班数</th>
        	<th rowspan="2">项目班级总数</th>
        	<th rowspan="2">进入率</th>
        	<th rowspan="2">总覆盖率</th>
        </tr>
        <tr>
        	<th>逐校</th>
        	<th>总计</th>
        	<th>逐校</th>
        	<th>总计</th>
        </tr>
        
        <tbody id="school">
        {foreach $feedbacks.school as $sid => $feedback}
        <tr>
        	<td>{$schools[$sid].name|escape}</td>
        	<td class="enter_{$feedback.enter_status}">{$enter_status[$feedback.enter_status]}</td>
        	<td class="cover_grade">{$feedback.enter_total|default:0}</td>
        	<td class="exists_grade">{$schools[$sid].grade_total_num}</td>
        	<td>&nbsp;</td>
        	{if $feedback@first}<td rowspan="{$feedback@total}">&nbsp;</td>{/if}
        	<td>&nbsp;</td>
        	{if $feedback@first}
        	<td rowspan="{$feedback@total}">&nbsp;</td>
        	<td rowspan="{$feedback@total}" class="time_total">{date_sub from=$project.start_time to=$project.end_time format='%a'}</td>
        	<td rowspan="{$feedback@total}" class="cover_grade_total">0</td>
        	<td rowspan="{$feedback@total}" class="exists_grade_total">0</td>
        	<td rowspan="{$feedback@total}" class="enter_rate">0</td>
        	<td rowspan="{$feedback@total}" class="cover_rate">0</td>
        	{/if}
        </tr>
        {/foreach}
        </tbody>
        
        <tr>
        	<th rowspan="2">项目成员</th>
        	<th rowspan="2">项目学校</th>
        	<th rowspan="2">是否进入</th>
        	<th colspan="2">覆盖班数</th>
        	<th colspan="2">学校班数</th>
        	<th rowspan="2">进入率</th>
        	<th colspan="2">贡献率</th>
        	<th rowspan="2">满点提成（%）</th>
        	<th rowspan="2">实际工作时长</th>
        	<th rowspan="2">实际提成比例（%）</th>
        </tr>
        <tr>
        	<th>逐校</th>
        	<th>总计</th>
        	<th>逐校</th>
        	<th>总计</th>
        	<th>逐校</th>
        	<th>总计</th>
        </tr>
        
        {foreach $feedbacks.member as $mid => $member}
        <tbody class="member">
        	{foreach $member as $sid => $feedback}
        	<tr>
	        	{if $feedback@first}<td rowspan="{$feedback@total}">{$members[$mid].name|escape}</td>{/if}
	        	<td>{$schools[$sid].name|escape}</td>
	        	<td class="enter_{$feedback.enter_status}">{$enter_status[$feedback.enter_status]}</td>
	        	<td class="cover_grade">{$feedback.enter_total}</td>
	        	{if $feedback@first}<td rowspan="{$feedback@total}" class="cover_grade_total">0</td>{/if}
	        	<td class="exists_grade">{$schools[$sid].grade_total_num}</td>
	        	{if $feedback@first}
	        	<td rowspan="{$feedback@total}" class="exists_grade_total"></td>
	        	<td rowspan="{$feedback@total}" class="enter_rate"></td>
	        	{/if}
	        	<td class="devote_rate"></td>
	        	{if $feedback@first}
	        	<td rowspan="{$feedback@total}" class="devote_total"></td>
	        	<td rowspan="{$feedback@total}" class="give_point">{$members[$mid].point}</td>
	        	<td rowspan="{$feedback@total}" class="work_time">{$members[$mid].work_time}</td>
	        	<td rowspan="{$feedback@total}" class="real_give_point"></td>
	        	{/if}
	        </tr>
        	{/foreach}
        </tbody>
        {/foreach}
    </table>
    
    <a href="/market/se/project/edit/page?id={$project.id|escape}">编辑项目</a>
    &nbsp;|&nbsp;
    <a href="#" onclick="delete_project()">删除项目</a>

</div>
{/block}
